// components/home-tab/index.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },
  /**
   * 页面的初始数据
   */
  data: {
    barHeight:40,
    allWork:0,
    allFinish:0,
    allUnFinish:0,
  },

   /**
   * 组件的方法列表
   */
  methods: {
    refreshData() {
      // 这里写具体的数据加载逻辑
      this.getNum()
      console.log('底部标签数据刷新');

    },
    async getNum(){
      let res= await getApp().db.collection('work').get()
      console.log('长度',res.data.length);
      let getUnFinish=0;
      let getFinish=0
      if(res.data && res.data.length > 0){
        for(let i=0;i < res.data.length;i++){
          const item = res.data[i]
          if (item.status === '待接单' || item.status === '待处理') {
            getUnFinish++
          }
          if(item.status==='已办结'){
            getFinish++
          }
        }
      }
      this.setData({
        allWork:res.data.length,
        allUnFinish:getUnFinish,
        allFinish:getFinish
      })
    },
    handleGetAllWork(ev){
      console.log('点击事件所带参数',ev);
      let status=ev.currentTarget.dataset.status
      wx.navigateTo({
        url: `../../package_work/pages/allWork/index?`+`status=${status}`,
      })
    }
  },
  lifetimes:{
    attached(){
      let info=wx.getWindowInfo()
      console.log(info);
      this.setData({
        barHeight:info.statusBarHeight*2-20,
      })
      this.getNum();
    }
  }
})